package com.fled.itsmbigscreen.controller;

import com.fled.itsmbigscreen.dto.FindHighBugClient.FindHighBugClientDto;
import com.fled.itsmbigscreen.dto.GroupAddDto;
import com.fled.itsmbigscreen.dto.GroupDelDto;
import com.fled.itsmbigscreen.dto.GroupEditNameDto;
import com.fled.itsmbigscreen.dto.clientInfoDto.ClientListDto;
import com.fled.itsmbigscreen.dto.clientListDto.ClientListData;
import com.fled.itsmbigscreen.dto.groupDto.HuorongBaseList;
import com.fled.itsmbigscreen.response.BaseResult;
import com.fled.itsmbigscreen.response.RetResponse;
import com.fled.itsmbigscreen.service.HuorongService;
import com.fled.itsmbigscreen.service.PduService;
import com.fled.itsmbigscreen.vo.GetElectricityByRoomIdVo;
import com.fled.itsmbigscreen.vo.GetSensorByRoomIdVo;
import com.fled.itsmbigscreen.vo.GroupAddVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "pdu接口")
@CrossOrigin
@RequestMapping("/pdu")
@RestController
public class PduController {


    @Autowired
    private PduService pduService;


//
    @ApiOperation("根据机房id获取PDU历史温湿度")
    @GetMapping("/getSensorByRoomId")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GetSensorByRoomIdVo.class)
    })
    public BaseResult getSensorByRoomId(Integer roomId) {
        try {
         List<GetSensorByRoomIdVo> getSensorByRoomIdVo = pduService.getSensorByRoomId(roomId);
            return RetResponse.makeOKRsp(getSensorByRoomIdVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("根据机房id获取PDU平均电力电压功率")
    @GetMapping("/getElectricityByRoomId")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GetElectricityByRoomIdVo.class)
    })
    public BaseResult getElectricityByRoomId(Integer roomId) {
        try {
            GetElectricityByRoomIdVo getElectricityByRoomIdVo = pduService.getElectricityByRoomId(roomId);
            return RetResponse.makeOKRsp(getElectricityByRoomIdVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("获取今日能耗")
    @GetMapping("/getPower")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GetElectricityByRoomIdVo.class)
    })
    public BaseResult getPower() {
        try {
            Double power = pduService.getPower();
            return RetResponse.makeOKRsp(power);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("获取告警总数")
    @GetMapping("/getAlert")
    @ResponseBody
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GetElectricityByRoomIdVo.class)
    })
    public BaseResult getAlert() {
        try {
            Integer num = pduService.getAlert();
            return RetResponse.makeOKRsp(num);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 发送邮件测试
     *
     * @param
     * @return
     */
    @ApiOperation("发送邮件测试")
    @GetMapping("/sendMail")
    @ResponseBody
    public BaseResult sendMail(String subject,String context) {
        try {
            pduService.sendMail( subject, context);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }





}
